/*
 * @Description  :
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2022-01-18 15:57:44
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-04-11 14:26:38
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\financial-management\\services\\freight-account.service.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Injectable, Injector } from '@angular/core';
import { BaseService, EACacheService, ShipperBaseService } from '@shared';

@Injectable({
  providedIn: 'root'
})
export class FreightAccountService extends ShipperBaseService {
  $mock_url = '/rule?_allow_anonymous=true';

  // 运营端获取货主账户信息
  $api_get_shipper_account_page = '/api/fcc/accountBalance/getShipperAccountBalanceByOperator';
  // 运营端获取司机账户信息
  $api_get_driver_account_page = '/api/fcc/accountBalance/getDriverAccountBalanceByOperator';

  // 运营端获取平台余额
  $api_get_platform_account_header = '/api/fcc/accountBalance/getPlatformBalanceByOperator';
  // 运营端获取平台余额
  $api_get_platform_account_statistics = '/api/fcc/accountBalanceDetail/getAccountBalancePlatformIncomeDetailByOperator';
  // 运营端获取平台余额
  $api_get_platform_account_page = '/api/fcc/accountBalance/getPlatformAccountBalanceByOperator';
  // 运营端获取账户余额交易明细
  $api_get_platform_account_detail_page = '/api/fcc/accountBalanceDetail/getAccountBalanceByPage';

  // 运营端获取货主账户明细信息
  $api_get_shipper_account_detail = '/api/fcc/accountBalanceDetail/getAccountBalanceShipperByOperatorPage';
  // 运营端获取司机账户明细信息
  $api_get_driver_account_detail = '/api/fcc/accountBalanceDetail/getAccountBalanceDriverByOperatorPage';
  // 运营端端获取货主交易收入与支出金额
  $api_get_shipper_account_balance_detail = '/api/fcc/accountBalanceDetail/getAccountBalanceShipperIncomeDetailByOperator';
  // 运营端端获取司机交易收入与支出金额
  $api_get_driver_account_balance_detail = '/api/fcc/accountBalanceDetail/getAccountBalanceDriverIncomeDetailByOperator';
  // 运营端导出司机账户明细信息
  $api_export_driver_account_page = '/api/fcc/accountBalance/exportDriverAccountBalanceByOperator';

  // 货主端获取账户余额交易明细
  $api_get_balance_by_shipper = '/api/fcc/accountBalanceDetail/getAccountBalanceByShipperPage';
  // 运营端导出货主账户明细信息
  $api_export_shipper = '/api/fcc/accountBalance/reportShipperAccountBalanceByOperator';

  // 查询订单支付申请表
  $api_get_order_payment_page = '/api/fcc/billPaymentApplicationOBC/list/page';

  // 查询提现申请表
  $api_get_refund_page = '/api/fcc/refundApplicationOBC/list/page';
  // 获取提现申请表详情
  $api_get_refund_detail = '/api/fcc/refundApplicationOBC/get';
  // 获取提现支付详情
  $api_get_refund_detail_page = '/api/fcc/refundApplicationOBC/get/getPayList';
  // 提现支付详情导出
  $api_export_refund_detail_page = '/api/fcc/refundApplicationOBC/asyncExportPayList';
  // 同意提现
  $api_agree_refund = '/api/fcc/refundApplicationOBC/agreeRefund';
  // 拒绝提现
  $api_disagree_refund = '/api/fcc/refundApplicationOBC/disagreeRefund';

  // 查询订单退款申请表
  $api_get_refund_record_page = '/api/fcc/billRefundApplication/list/page';
  // 同意退款
  $api_agree_refund_record = '/api/fcc/billRefundApplication/agreeRefund';
  // 不同意退款
  $api_disagree_refund_record = '/api/fcc/billRefundApplication/disagreeRefund';
  // 重新发起
  $api_rebulid_refund_record = '/api/fcc/billRefundApplication/rebulid';

  // 查询充值信息表
  $api_get_recharge_page = '/api/fcc/rechargeInfo/list/getPageByOperator';
  // 查询异常入金
  $api_get_abnormal_gold_page = '/api/fcc/rechargeInfo/list/page';
  // 运营端获取账户余额交易明细
  $api_get_account_blance = '/api/fcc/accountBalanceDetail/getAccountBalanceByPage';
  // 添加备注
  $api_edit_remark = '/api/fcc/rechargeInfo/addRemark';

  // 查询费用单抬头
  $api_get_cost_page = '/api/fcc/ficoFeeH/list/page';
  // 导出费用单列表数据
  $api_get_cost_page_export = '/api/fcc/ficoFeeH/asyncExport';
  // 导出费用管理列表数据
  $api_get_reportFeehList = '/api/fcc/ficoFeeH/reportFeehList';
  // 根据费用头ID查询费用单及开票明细
  $api_get_cost_detail = '/api/fcc/ficoFeeL/detail';
  // 费用关联的应收核销明细
  $api_get_cost_ahxl_detail = '/api/fcc/ficoAhxL/getListByFeeLId';

  // 查询应收核销抬头
  $api_get_fico_page = '/api/fcc/ficoAhxH/list/page';
  // 应收核销列表数据导出
  $api_get_fico_page_export = '/api/fcc/ficoAhxH/asyncExport';
  // 应收核销汇总
  $api_get_fico_sum = '/api/fcc/ficoAhxH/getSum';
  // 获取应收核销抬头
  $api_get_fico_header = '/api/fcc/ficoAhxH/get';
  // 查询应收核销明细
  $api_get_fico_detail_header = '/api/fcc/ficoAhxL/list/page';

  // 查询应付核销抬头
  $api_get_fico_ph_page = '/api/fcc/ficoPhxH/list/page';
  // 应付核销列表数据导出
  $api_get_fico_ph_page_export = '/api/fcc/ficoPhxH/asyncExport';
  // 应付核销汇总
  $api_get_fico_ph_sum = '/api/fcc/ficoPhxH/getSum';
  // 获取应付核销抬头
  $api_get_fico_ph_header = '/api/fcc/ficoPhxH/get';
  // 查询应付核销明细
  $api_get_fico_ph_detail_header = '/api/fcc/ficoPhxL/list/page';

  // 查询总账凭证表
  $api_get_fico_vch_page = '/api/fcc/ficoVcH/list/page';
  // 导出总账凭证列表数据
  $api_get_fico_vch_export = '/api/fcc/ficoVcH/asyncExport';
  // 导出总账凭证表
  $api_export_fico_vch_page = '/api/fcc/ficoVcH/reportVchListPage';
  // 获取总账凭证表详情信息
  $api_get_fico_vch__detail = '/api/fcc/ficoVcH/getDetail';

  // 查询付款单抬头
  $api_get_payment_page = '/api/fcc/ficoPayH/listFicoPayHPage';
  // 付款单列表数据导出
  $api_get_payment_page_export = '/api/fcc/ficoPayH/asyncExport';
  // 查询付款单明细
  $api_get_payment_detail = '/api/fcc/ficoPayL/list/page';
  // 付款单抬头信息
  $api_get_payment_header = '/api/fcc/ficoPayH/getFicoPayHById';

  // 查询收款单抬头
  $api_get_receipt_page = '/api/fcc/ficoBrmH/list/page';
  // 收款单列表数据导出
  $api_get_receipt_page_export = '/api/fcc/ficoBrmH/asyncExport';
  // 收款单抬头信息
  $api_get_receipt_header = '/api/fcc/ficoBrmH/get';
  // 获取收款单抬头
  $api_get_receipt_detail = '/api/fcc/ficoBrmYsk/getListByBrmHid';

  // 收款单浏览抬头
  $api_get_ficoInpinvL_page = '/api/fcc/ficoBrmH/get';
  // 收款单浏览表格明细
  $api_get_ficoInpinvL_getListByBrmHid = '/api/fcc/ficoBrmYsk/getListByBrmHid';

  // 下载银行回单请求
  $api_download_receipt_apply = '/api/fcc/spd/callback/receiptApply';
  $api_download_receipt_apply_byte = '/api/fcc/spd/callback/receiptApplyByte';

  // 查询预收款余额
  $api_get_advance_collection_page = '/api/fcc/ficoYskBla/list/page';
  // 根据预收款ID获取收款单抬头
  $api_get_advance_collection_header = '/api/fcc/ficoBrmH/getByYskblaId';
  // 根据预收款ID获取收款单明细
  $api_get_advance_collection_detail = '/api/fcc/ficoBrmYsk/getBrmYskByYskblaId';
  // 根据预收款ID获取核销信息明细
  $api_get_advance_collection_hrxiao = '/api/fcc/ficoAhxH/getAhxHByYskblaId';

  // 运营导出充值信息 充值记录导出
  $api_get_exportPageByOperator = '/api/fcc/rechargeInfo/exportPageByOperator';
  // 运营端导出交易流水明细
  $api_get_exportAccountBalanceDetailPage = '/api/fcc/accountBalanceDetail/exportAccountBalanceDetailPage';
  // 运营端导出平台账户余额交易明细
  $api_get_exportAccountBalanceByPage = '/api/fcc/accountBalanceDetail/exportAccountBalanceByPage';
  // 运营端导出司机账户余额交易明细
  $api_get_exportAccountBalanceDriverByOperatorPage = '/api/fcc/accountBalanceDetail/exportAccountBalanceDriverByOperatorPage';
  // 运营端导出货主账户余额交易明细
  $api_get_exportAccountBalanceShipperByOperatorPage = '/api/fcc/accountBalanceDetail/exportAccountBalanceShipperByOperatorPage';
  // 运营端导出导出货主账户
  $api_get_exportShipperAccountBalanceByOperator = '/api/fcc/accountBalance/exportShipperAccountBalanceByOperator';
  // 运营端导出导出平台账户信息
  $api_get_exportPlatformAccountBalanceByOperator = '/api/fcc/accountBalance/exportPlatformAccountBalanceByOperator';
  // 导出预收款余额
  $api_get_reportYskBla = '/api/fcc/ficoYskBla/reportYskBla';

  // 查询异常入金充值信息
  $api_get_getAbnormalAmountPage = '/api/fcc/rechargeInfo/list/getAbnormalAmountPage';
  // 查询异常入金充值信息详情
  $api_get_getAbnormalAmount_detail = '/api/fcc/rechargeInfo/get';

  // 异步导出运营后台异常入金列表
  $api_get_exportAbnormalAmountPage = '/api/fcc/rechargeInfo/exportAbnormalAmountPage';
  // 异步导出运营后台退款记录列表
  $api_get_asyncExportBillRefundApplicationList = '/api/fcc/billRefundApplication/asyncExportBillRefundApplicationList';
  // 异步导出运营后台支付记录列表
  $api_get_asyncExportBillPaymentApplicationList = '/api/fcc/billPaymentApplicationOBC/asyncExportBillPaymentApplicationList';
  // 异步导出运营后台提现记录
  $api_get_asyncExportRefundApplicationList = '/api/fcc/refundApplicationOBC/asyncExportRefundApplicationList';

  constructor(public injector: Injector) {
    super(injector);
  }

  getReceiptUrl(url: string, params: any) {
    const { bankType, snglFlgCd } = params;
    if (url) {
      if (params?.bankType === '1') {
        window.open(url);
      } else if (params?.bankType === '2') {
        window.open(url);
        // this.exportFile({ bankType, receiptUrl: url, bankSerialNumber: snglFlgCd }, this.$api_download_receipt_apply_byte);
      }
    } else {
      this.request(this.$api_download_receipt_apply, { ...params }).subscribe(res => {
        if (res?.receiptUrl) {
          if (bankType === '1') {
            window.open(res?.receiptUrl);
          } else if (bankType === '2') {
            window.open(res?.receiptUrl);
            // this.downloadFile(this.$api_download_receipt_apply_byte, {
            //   bankType,
            //   receiptUrl: res.receiptUrl,
            //   bankSerialNumber: snglFlgCd
            // });
          }
        } else {
          this.msgSrv.warning(res.statusMsg || '获取回单失败');
        }
      });
    }
  }
  // 获取货主企业列表
  public $api_enterpriceList = '/api/mdc/cuc/enterpriseInfo/operate/enterpriceList';
  // 获取企业CRM信息
  public $api_crm_enterpriceList = '/api/mdc/cuc/enterprise/getCrmSelectList';
  reviewPDF(url: string) {
    if (!url) {
      return;
    }
    this.openURL(url);
    // const uA = window.navigator.userAgent; // 判断浏览器内核
    // const isIE =
    //   /msie\s|trident\/|edge\//i.test(uA) &&
    //   !!('uniqueID' in document || 'documentMode' in document || 'ActiveXObject' in window || 'MSInputMethodContext' in window);
    // const objectUrl = url;
    // const a = document.createElement('a');
    // document.body.appendChild(a);
    // a.href = objectUrl;
    // a.download = `回单.pdf`;
    // if (isIE) {
    //   // 兼容IE11无法触发下载的问题
    //   (navigator as any).msSaveBlob(url, a.download);
    // } else {
    //   a.click();
    // }
    // a.remove();
  }
}
